package com.nq.controller.agent;

import com.nq.common.ServerResponse;
import com.nq.pojo.User;
import com.nq.pojo.UserBank;
import com.nq.service.IAgentUserService;
import com.nq.service.IUserBankService;
import com.nq.service.IUserService;
import javax.servlet.http.HttpServletRequest;

import com.nq.service.SmsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping({"/agent/user/"})
public class AgentUserController {
    private static final Logger log = LoggerFactory.getLogger(AgentUserController.class);

    @Autowired
    IUserService iUserService;
    @Autowired
    IAgentUserService iAgentUserService;
    @Autowired
    SmsService smsService;
    @Autowired
    IUserBankService iUserBankService;

    //分页查询用户管理信息及模糊查询
    @RequestMapping({"list.do"})
    @ResponseBody
    public ServerResponse list(@RequestParam(value = "realName", required = false) String realName,
                               @RequestParam(value = "userId", required = false) Integer userId,
                               @RequestParam(value = "isRecharge", required = false) Integer isRecharge,
                               @RequestParam(value = "phone", required = false) String phone,
                               @RequestParam(value = "agentId", required = false) Integer agentId,
                               @RequestParam(value = "accountType", required = false) Integer accountType,
                               @RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
                               @RequestParam(value = "pageSize", defaultValue = "10") int pageSize,
                               @RequestParam(value = "isActive", required = false) Integer isActive,
                               HttpServletRequest request) {
        return this.iUserService.listByAgent(userId, isRecharge, realName, phone, agentId, accountType, pageNum, pageSize, isActive, request);
    }

    /**
     * 修改用户列表 用户资金手动入款/扣款
     * @param userId
     * @param amt
     * @param direction
     * @param request
     * @return
     */
    @RequestMapping({"updateAmt.do"})
    @ResponseBody
    public ServerResponse updateAmt(Integer userId, String amt, Integer direction, HttpServletRequest request) {
        //amt转Integer
        return this.iUserService.updateAgentAmt(userId, amt, direction, request);
    }

    //修改用户列表 用户资金入款/扣款
    @RequestMapping({"deleteById.do"})
    @ResponseBody
    public ServerResponse deleteById(Integer userId,HttpServletRequest request) {
        //amt转Integer
        return this.iUserService.agentDelete(userId, request);
    }

    /**
     * 代理-审核身份证信息
     * @param userId
     * @param state
     * @param authMsg
     * @return
     */
    @RequestMapping({"authByAgent.do"})
    @ResponseBody
    public ServerResponse authByAgent(Integer userId, Integer state, String authMsg) {
        ServerResponse response = this.iUserService.authByAgent(userId, state, authMsg);
        return response;
    }

    //修改用户列表 用户信息
    @RequestMapping({"update.do"})
    @ResponseBody
    public ServerResponse update(User user) {
        return this.iUserService.update(user);
    }

    //查看指定 用户列表的用户信息
    @RequestMapping({"getBank.do"})
    @ResponseBody
    public ServerResponse getBank(Integer userId) {
        return this.iUserBankService.getBank(userId);
    }

    /**
     * 更新用户银行卡信息
     * @param userBank
     * @return
     */
    @RequestMapping({"updateBank.do"})
    @ResponseBody
    public ServerResponse updateBank(UserBank userBank) {

        int flag = iUserBankService.updateBankByUserId(userBank);
        if (flag > 0) {
            return ServerResponse.createBySuccess(flag);
        }
        return ServerResponse.createByErrorMsg("fail");
    }

    /**
     * 查询用户上下级
     * @param userId
     * @return
     */
    @RequestMapping({"getSuperiorAndSubordinate.do"})
    @ResponseBody
    public ServerResponse getSuperiorAndSubordinate(Integer userId) {
        return this.iUserService.getSuperiorAndSubordinate(userId);
    }
}
